<template>
  <div class="list">

    <div class="content-head" style="margin-bottom: 20px;">
      <div class="sort-keys">
      

        <span style="margin-left: 20px; margin-right: 6px;">日期:</span>
        <iDatePicker :showTime="false" style="margin-left: 10px;" placeholder="不选则不限制" v-model="filter.min_day"></iDatePicker>
        至
        <iDatePicker :showTime="false" style="margin-left: 0px;" placeholder="不选则不限制" v-model="filter.max_day"></iDatePicker>


      </div>
    </div>
    <a-table class="table" :rowKey="row => row.uuid" :dataSource="list" :pagination="pagination" :size="size">

      <a-table-column title="用户" width="120px">
        <template slot-scope="row">
          <div class="user" v-if="row.user">
            <img :src="row.user.headimg" alt="用户头像">
            <div>
              <div>{{ row.user.name }}</div>
              <div>{{row.user.phone}}</div>
            </div>
            <a-tag color="red" style="margin-left:10px;" v-if="row.user.status === 2">已拉黑</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_rb === 1">马甲</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_rb2 === 1">主播</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_liu === 1">老六</a-tag>
                <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_nopay === 1">禁付</a-tag>
                <a-tag color="blue" style="margin-left:10px;" v-if="row.user.click_id">微广</a-tag>
          </div>
        </template>
      </a-table-column>
      <a-table-column title="微信群" width="80px" >
        <template slot-scope="row">
          <a-tag style="margin-left:10px;" v-for="(item, index) in row.qy_groups">{{item}}</a-tag>
        </template>
      </a-table-column>
      <a-table-column
        title="注册日期"
        width="110px"
      >
        <template slot-scope="row">
          <span v-if="row.user" :style="row.user.created_at | parseStyle">{{ row.user.created_at | formatDate }}</span>
        </template>
      </a-table-column>
      <a-table-column title="总支付" width="100px">
        <template slot-scope="row">
          <NumberGroupDisplay :info="row" prefix="sum_pay_"></NumberGroupDisplay>
        </template>
      </a-table-column>

      <a-table-column title="充值支付" width="100px">
        <template slot-scope="row">
          <NumberGroupDisplay :info="row" prefix="other_pay_"></NumberGroupDisplay>
        </template>
      </a-table-column>

      <a-table-column title="福袋支付" width="100px">
        <template slot-scope="row">
          <NumberGroupDisplay :info="row" prefix="fudai_pay_"></NumberGroupDisplay>
        </template>
      </a-table-column>

      <a-table-column title="一番赏支付" width="100px">
        <template slot-scope="row">
          <NumberGroupDisplay :info="row" prefix="yfs_pay_"></NumberGroupDisplay>
        </template>
      </a-table-column>

      <a-table-column title="连击赏支付" width="100px">
        <template slot-scope="row">
          <NumberGroupDisplay :info="row" prefix="renyi_pay_"></NumberGroupDisplay>
        </template>
      </a-table-column>

      <a-table-column title="卡牌社支付" width="100px">
        <template slot-scope="row">
          <NumberGroupDisplay :info="row" prefix="kapaishe_pay_"></NumberGroupDisplay>
        </template>
      </a-table-column>

      <a-table-column title="发起提现" width="100px">
        <template slot-scope="row">
          <NumberGroupDisplay :info="row" prefix="tx_pay_"></NumberGroupDisplay>
        </template>
      </a-table-column>

      <a-table-column title="发货订单红包价值" width="100px">
        <template slot-scope="row">
          <NumberGroupDisplay :info="row" prefix="send_pay_"></NumberGroupDisplay>
        </template>
      </a-table-column>

    </a-table>

  </div>
</template>
<script>
  import moment from 'moment'
  import ISwitch from '@/components/ISwitch/ISwitch'

  import NumberGroupDisplay from './components/NumberGroupDisplay'

  import IDatePicker from "@/components/IDatePicker/IDatePicker.vue"

  const resourceType = 'stats/user-stats'
  const resourceTypeText = '消费统计'

  export default {
    components: {
      ISwitch,
      NumberGroupDisplay,
      IDatePicker
    },
    props: {
      selectMode: {
        type: Boolean
      },
      params: {
        type: Object
      },
      size: {
        type: String,
        default: 'default'
      }
    },
    data() {
      return {
        list: [],
        page: 1,
        per_page: 10,
        total: 0,
        filter: {
          min_day: '',
          max_day: ''
        }
      }
    },
    watch: {
      params() {
        this.refreshData()
      },
      'filter.min_day'() {
        if(this.filter.min_day && this.filter.max_day){
          this.refreshData()
        }else if(!this.filter.min_day && !this.filter.max_day){
          this.refreshData()
        }
      },
      'filter.max_day'() {
        if(this.filter.min_day && this.filter.max_day){
          this.refreshData()
        }else if(!this.filter.min_day && !this.filter.max_day){
          this.refreshData()
        }
      }
    },
    computed: {
      
    },
    filters: {
      parseStyle (value) {
        if(new Date(value).getTime() >= (new Date().getTime() - 86400*2000) ){
            return `color:red;`
        }
      },
      formatDate (value) {
        return value ? moment(value).fromNow() : ''
        
      },
      formatDate2 (value) {
        return value ? moment(value).format('YYYY-MM-DD HH:mm') : ''
      },
    },
    created() {
      this.fetchData()
    },
    methods: {
      refreshData() {
        this.page = 1
        this.fetchData()
      },
      fetchData() {
        this.isEdit = false
        this.$http.get(`/recharge-ranked`, {
          params: {
            ...this.params,
            page: this.page,
            per_page: this.per_page,
            sort_by: this.sortBy,
            min_day: this.filter.min_day,
            max_day: this.filter.max_day
          }
        }).then(res => {
          this.list = res.data.list
          this.total = res.data.item_total
        }).finally(() => {
          this.loading = false
        })
      },
    }
  }
</script>
<style lang="scss" scoped>
  .top-btn {
    background: #1890FF;
    color: white;
    cursor: pointer;
    font-size: 80%;
    border-radius: 4px;
    padding: 2px 6px;

    &.unset {
      border: 1px solid #D8D5D5;
      background: #D8D5D5;
      color: gray;
    }
  }

  .content-head {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .table {
    .thumb {
      height: 60px;
      border-radius: 6px;
    }

    .content-image {
      height: 60px;
      width: 60px;
      margin-right: 10px;
      margin-bottom: 10px;
      object-fit: cover;
      border-radius: 10px;
      cursor: pointer;

      &:hover {
        opacity: 0.8;
      }
    }

    .user {
      display: flex;
      // flex-wrap: wrap;
      align-items: center;

      img {
        width: 26px;
        height: 26px;
        margin-right: 6px;
        border-radius: 50%;
        overflow: hidden;
      }

      .gender-man,
      .gender-woman {
        margin-left: 5px;
        font-size: 12px;
      }

      .gender-man {
        color: #409EFF;
      }

      .gender-woman {
        color: #F56C6C;
      }
    }
  }
</style>
